from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-05-04 14:02:28.411071
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Wed, 04, May, 2022
Time: 14:02:34
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -49.1672
Nobs: 646.000 HQIC: -49.5484
Log likelihood: 7922.48 FPE: 2.37938e-22
AIC: -49.7901 Det(Omega_mle): 2.07215e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.325567 0.061591 5.286 0.000
L1.Burgenland 0.105128 0.039226 2.680 0.007
L1.Kärnten -0.110300 0.020567 -5.363 0.000
L1.Niederösterreich 0.195760 0.081879 2.391 0.017
L1.Oberösterreich 0.118290 0.080866 1.463 0.144
L1.Salzburg 0.258764 0.041678 6.209 0.000
L1.Steiermark 0.043798 0.054807 0.799 0.424
L1.Tirol 0.105806 0.044201 2.394 0.017
L1.Vorarlberg -0.063397 0.039043 -1.624 0.104
L1.Wien 0.026468 0.071633 0.369 0.712
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.052007 0.131647 0.395 0.693
L1.Burgenland -0.032840 0.083844 -0.392 0.695
L1.Kärnten 0.040211 0.043961 0.915 0.360
L1.Niederösterreich -0.190050 0.175013 -1.086 0.278
L1.Oberösterreich 0.447497 0.172848 2.589 0.010
L1.Salzburg 0.285966 0.089084 3.210 0.001
L1.Steiermark 0.105999 0.117147 0.905 0.366
L1.Tirol 0.313863 0.094477 3.322 0.001
L1.Vorarlberg 0.022324 0.083453 0.268 0.789
L1.Wien -0.036572 0.153113 -0.239 0.811
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.189956 0.031570 6.017 0.000
L1.Burgenland 0.090361 0.020107 4.494 0.000
L1.Kärnten -0.007926 0.010542 -0.752 0.452
L1.Niederösterreich 0.248658 0.041970 5.925 0.000
L1.Oberösterreich 0.156818 0.041450 3.783 0.000
L1.Salzburg 0.040837 0.021363 1.912 0.056
L1.Steiermark 0.024963 0.028093 0.889 0.374
L1.Tirol 0.086616 0.022656 3.823 0.000
L1.Vorarlberg 0.054670 0.020013 2.732 0.006
L1.Wien 0.116528 0.036718 3.174 0.002
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.112560 0.031703 3.550 0.000
L1.Burgenland 0.045443 0.020191 2.251 0.024
L1.Kärnten -0.014310 0.010586 -1.352 0.176
L1.Niederösterreich 0.180518 0.042146 4.283 0.000
L1.Oberösterreich 0.326967 0.041624 7.855 0.000
L1.Salzburg 0.101825 0.021453 4.746 0.000
L1.Steiermark 0.110321 0.028211 3.911 0.000
L1.Tirol 0.097690 0.022751 4.294 0.000
L1.Vorarlberg 0.059487 0.020097 2.960 0.003
L1.Wien -0.021229 0.036872 -0.576 0.565
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.115241 0.059037 1.952 0.051
L1.Burgenland -0.043185 0.037600 -1.149 0.251
L1.Kärnten -0.046471 0.019714 -2.357 0.018
L1.Niederösterreich 0.143607 0.078485 1.830 0.067
L1.Oberösterreich 0.157521 0.077514 2.032 0.042
L1.Salzburg 0.283529 0.039950 7.097 0.000
L1.Steiermark 0.055820 0.052535 1.063 0.288
L1.Tirol 0.166643 0.042368 3.933 0.000
L1.Vorarlberg 0.096259 0.037425 2.572 0.010
L1.Wien 0.073271 0.068664 1.067 0.286
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.059286 0.046511 1.275 0.202
L1.Burgenland 0.030617 0.029622 1.034 0.301
L1.Kärnten 0.051552 0.015531 3.319 0.001
L1.Niederösterreich 0.204462 0.061832 3.307 0.001
L1.Oberösterreich 0.321308 0.061067 5.262 0.000
L1.Salzburg 0.039227 0.031473 1.246 0.213
L1.Steiermark 0.007098 0.041388 0.172 0.864
L1.Tirol 0.130453 0.033379 3.908 0.000
L1.Vorarlberg 0.065284 0.029484 2.214 0.027
L1.Wien 0.091493 0.054095 1.691 0.091
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.172983 0.055833 3.098 0.002
L1.Burgenland 0.005763 0.035559 0.162 0.871
L1.Kärnten -0.065255 0.018644 -3.500 0.000
L1.Niederösterreich -0.096522 0.074225 -1.300 0.193
L1.Oberösterreich 0.205034 0.073306 2.797 0.005
L1.Salzburg 0.054491 0.037781 1.442 0.149
L1.Steiermark 0.240064 0.049683 4.832 0.000
L1.Tirol 0.501182 0.040068 12.508 0.000
L1.Vorarlberg 0.060127 0.035393 1.699 0.089
L1.Wien -0.075446 0.064937 -1.162 0.245
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.148233 0.061939 2.393 0.017
L1.Burgenland 0.004686 0.039448 0.119 0.905
L1.Kärnten 0.060020 0.020683 2.902 0.004
L1.Niederösterreich 0.184381 0.082342 2.239 0.025
L1.Oberösterreich -0.060809 0.081324 -0.748 0.455
L1.Salzburg 0.207354 0.041913 4.947 0.000
L1.Steiermark 0.134223 0.055117 2.435 0.015
L1.Tirol 0.070279 0.044451 1.581 0.114
L1.Vorarlberg 0.143474 0.039264 3.654 0.000
L1.Wien 0.110070 0.072039 1.528 0.127
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.377764 0.036424 10.371 0.000
L1.Burgenland -0.001078 0.023198 -0.046 0.963
L1.Kärnten -0.021817 0.012163 -1.794 0.073
L1.Niederösterreich 0.211061 0.048422 4.359 0.000
L1.Oberösterreich 0.225842 0.047823 4.722 0.000
L1.Salzburg 0.039004 0.024648 1.582 0.114
L1.Steiermark -0.013968 0.032412 -0.431 0.666
L1.Tirol 0.095344 0.026140 3.647 0.000
L1.Vorarlberg 0.053231 0.023090 2.305 0.021
L1.Wien 0.036756 0.042363 0.868 0.386
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.036152 0.113718 0.173124 0.141250 0.102829 0.084818 0.037937 0.210167
Kärnten 0.036152 1.000000 -0.021092 0.134308 0.052529 0.090276 0.441786 -0.060639 0.092529
Niederösterreich 0.113718 -0.021092 1.000000 0.322905 0.129942 0.284561 0.074663 0.161548 0.296147
Oberösterreich 0.173124 0.134308 0.322905 1.000000 0.221483 0.310037 0.168902 0.149420 0.249564
Salzburg 0.141250 0.052529 0.129942 0.221483 1.000000 0.132048 0.096644 0.113790 0.130104
Steiermark 0.102829 0.090276 0.284561 0.310037 0.132048 1.000000 0.138626 0.119774 0.049778
Tirol 0.084818 0.441786 0.074663 0.168902 0.096644 0.138626 1.000000 0.069198 0.148871
Vorarlberg 0.037937 -0.060639 0.161548 0.149420 0.113790 0.119774 0.069198 1.000000 0.006779
Wien 0.210167 0.092529 0.296147 0.249564 0.130104 0.049778 0.148871 0.006779 1.000000